<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8"/>
	<link id="easyuiTheme" rel="stylesheet" type="text/css" href="../jquery-easyui-1.5.3/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../jquery-easyui-1.5.3/themes/icon.css"/>
	<!--<link rel="stylesheet" type="text/css" href="../jquery-easyui-1.5.3/demo/demo.css"/> -->
    <script type="text/javascript" src="../jquery-easyui-1.5.3/jquery.min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../jquery-easyui-1.5.3/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript">
	    var contextPath = function() {
	        return  "/" + location.pathname.split("/")[1];
	    }
	    
		function getValue(name){
			var str=window.location.search;
			if (str.indexOf(name)!=-1){
				var pos_start=str.indexOf(name)+name.length+1;
				var pos_end=str.indexOf("&",pos_start);
				if (pos_end==-1){
					return str.substring(pos_start);
				} else {
					return str.substring(pos_start,pos_end);
				}
			} else {
				return "";
			}
		}
		
		var  themeName = getValue("theme");
		if (themeName!=""){
		    var cssurl  = $('#easyuiTheme').attr('href');  
		    var href = cssurl.substring(0, cssurl.indexOf('themes')) + 'themes/' + themeName + '/easyui.css';  
		    $('#easyuiTheme').attr('href', href);  
		}		
	    
	    //将表单数据转为json
	    function form2Json(id) {
	        var arr = $("#" + id).serializeArray();
	        var jsonStr = "";
	        jsonStr += '{';
	        for (var i = 0; i < arr.length; i++) {
	            if ( arr[i].value != '' ) {
	            	jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'	            	
	            }
	        }
	        if (jsonStr.length > 1) {
	        	jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
	        }
	        jsonStr += '}';
	        var json = JSON.parse(jsonStr);
	        return json;
	    }
	    
	    //将表单数据转为json格式的字符串，当然也可以JSON.stringify(data)
	    function form2JsonStr(id) {
	        var arr = $("#" + id).serializeArray();
	        var jsonStr = "";
	        jsonStr += '{';
	        for (var i = 0; i < arr.length; i++) {
	            if ( arr[i].value != '' ) {
	            	jsonStr += '"' + arr[i].name + '":"' + arr[i].value + '",'	            	
	            }
	        }
	        if (jsonStr.length > 1) {
	        	jsonStr = jsonStr.substring(0, (jsonStr.length - 1));
	        }
	        jsonStr += '}';
	        return jsonStr;
	    }
	</script>

</head>

<style>
    .datagrid-btable{
        width:100%;
    }
    .datagrid-header-inner{
        width:100%;
    }
    .datagrid-header{
        width:100%;
    }
    .datagrid-htable{
        width:100%;
    }
    .datagrid-cell{margin:auto;}
    .fitem{text-align:center}
    .ftitle{text-align:center}
</style>

<body>
<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',title:''">	  
        <table id="datagrid"  class="easyui-datagrid" style="width:100%;height:100%"></table>
        <div id="dgtoolbar">		
        	<form name="searchform" method="post" action="" id ="searchform">	
				<td width="70" height="30">
					<strong>&nbsp;类型：</strong>
				    <select id="search_policy_type" class="easyui-combobox" name="policy_type" editable="false">
				    	<option value="" selected="selected">全部</option>
				    	<option value="纸质保单">纸质保单</option>
				    	<option value="电子保单">电子保单</option>
				    </select>	    			
				</td>									
				<td width="70" height="30">
					<strong>&nbsp;接件日期：</strong>
					<input id="search_intro_time1" name="introTimeBegin" class="easyui-datebox" editable="fasle" style="width:90px"></input>					
					<strong>-</strong>
					<input id="search_intro_time2" name="introTimeEnd" class="easyui-datebox" editable="fasle" style="width:90px"></input>
				</td>
				<td width="70" height="30">
					<strong>&nbsp;投保日期：</strong>
					<input id="search_insure_time1" name="insureTimeBegin" class="easyui-datebox" editable="fasle" style="width:90px"></input>					
					<strong>-</strong>
					<input id="search_insure_time2" name="insureTimeEnd" class="easyui-datebox" editable="fasle" style="width:90px"></input>
				</td>			
				<td width="70" height="30">
					<strong>&nbsp;回销日期：</strong>
					<input id="search_receipt_time1" name="receiptTimeBegin" class="easyui-datebox" editable="fasle" style="width:90px"></input>					
					<strong>-</strong>
					<input id="search_receipt_time2" name="receiptTimeEnd" class="easyui-datebox" editable="fasle" style="width:90px"></input>
				</td>			
				<td width="70" height="30">
					<strong>&nbsp;退回日期：</strong>
					<input id="search_return_time1" name="returnTimeBegin" class="easyui-datebox" editable="fasle" style="width:90px"></input>					
					<strong>-</strong>
					<input id="search_return_time2" name="returnTimeEnd" class="easyui-datebox" editable="fasle" style="width:90px"></input>				
				</td>		
			</form>
			<a id="submit_condition">统计</a>
			<a id="reset_condition">重置</a>
        </div>
    </div>
</div>
</body>

<script type="text/javascript">

    $(function() {
    	$('#datagrid').datagrid({
    		loadMsg:'正在加载数据...',
    	    url:contextPath()+'/mdmis/countReceiptRateByProject',
    	    toolbar:'#dgtoolbar',
    	    queryParams: form2Json("searchform"),
            rownumbers: true,
            striped: true, //隔行显示颜色
            fit: true,
            fitColumns: false, //不自动适应列宽
            singleSelect: true, 
            sortName: 'receipt_rate',
            sortOrder: 'desc', //默认值是 'asc'
            remoteSort: false,
            loader: function(param, success, error) {
            	$.ajax({
            		type : $(this).datagrid("options").method,
            		url : $(this).datagrid("options").url,
            		dataType : 'json',
            		contentType : 'application/json;charset=utf-8', // 设置请求头信息
            		data : JSON.stringify(param),
            		success : function(result) {
            			//alert(result.data);
            			success(result);
            		}
            	});
            },
            rowStyler:function(index,row){
    			if (row.project=='广西汇总'){
    				return 'background-color:#B0C4DE;color:#4169E1;font-weight:bold;';
    			}
    		},
    		onDblClickCell:function(index,field,value){
    			if (field=='project'){
    				if (value!='广西汇总') {
    					var data = form2Json("searchform");
    					data["project"] = value;
    					window.open(contextPath()+'/mdmis/report_receiptrate_project_area.html?data=' + encodeURIComponent(JSON.stringify(data)), '_blank ');
    				}
    			}
    		},
    	    columns:[[
    			{field:'project',title:'项目',sortable:true,align:'center',width:80},
    			{field:'receipt_rate',title:'回销率',sortable:true,align:'right',width:60,
    				formatter: function(value,row,index){
    			        if (value) {
    			        	if (value==0){
    			        		return "0%";
    			        	} else {
        			        	return value.toFixed(5)*100 + "%";    			        		
    			        	}
    			        } else {
    			            return "0%";
    			        }
    				}	
    			},
    			{field:'total',title:'总件数',sortable:true,align:'right',width:60},
    			{field:'send',title:'寄送中',sortable:true,align:'right',width:60},
    			{field:'receipt',title:'已回销',sortable:true,align:'right',width:60},
    			{field:'backall',title:'已退回',sortable:true,align:'right',width:60},
    			{field:'intro',title:'已收未寄',sortable:true,align:'right',width:60},
    			{field:'unintro',title:'未到广西',sortable:true,align:'right',width:60},
    			{field:'withdrawal',title:'已撤件',sortable:true,align:'right',width:60},
    			{field:'surrender',title:'已退保',sortable:true,align:'right',width:60},
    	    ]]
    	});      	
    	  
		//点击搜索
		$("#submit_condition").linkbutton({ iconCls: 'icon-search', plain: true }).click(function () {
            $('#datagrid').datagrid({ queryParams: form2Json("searchform") });   
        });
		//点击重置
		$("#reset_condition").linkbutton({ iconCls: 'icon-reload', plain: true }).click(function () {
            $('#search_policy_type').combobox('select','');
            $('#search_intro_time1').textbox('setValue',''); 
            $('#search_intro_time2').textbox('setValue',''); 
            $('#search_insure_time1').textbox('setValue',''); 
            $('#search_insure_time2').textbox('setValue',''); 
            $('#search_receipt_time1').textbox('setValue',''); 
            $('#search_receipt_time2').textbox('setValue',''); 
            $('#search_return_time1').textbox('setValue',''); 
            $('#search_return_time2').textbox('setValue',''); 
            //$('#datagrid').datagrid('reload');  
            $('#datagrid').datagrid({ queryParams: form2Json("searchform") });   
        });
    });

</script>


</html>